<?php


namespace Mlym\CodeGeneration\InitGeneration\Model\Method;


use Mlym\CodeGeneration\ClassGeneration\MethodAbstract;

class GetSelectPage extends MethodAbstract
{

    function addMethodBody()
    {
        $method = $this->method;

        //配置返回类型
        $method->setReturnType('array');

        //配置方法参数
        $method->addParameter('pageNo', 1)->setType('int');
        $method->addParameter('pageSize', 10)->setType('int');
        $method->addParameter('key', 'id')->setType('string');
        $method->addParameter('value', 'name')->setType('string');

        $methodBody = '';
        $methodBody .= <<<Body
        
\$list = \$this
    ->withTotalCount()
	->order(\$this->schemaInfo()->getPkFiledName(), 'DESC')
    ->field([\$key, \$value])
    ->page(\$pageNo, \$pageSize)
    ->all();
\$total = \$this->lastQueryResult()->getTotalCount();
\$data = [
    'list' => \$list,
    'total' => \$total,
];
return \$data;
Body;
        //配置方法内容
        $method->setBody($methodBody);
    }

    function getMethodName(): string
    {
        return 'getSelectPage';
    }
}